<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://"
          + request.getServerName() + ":" + request.getServerPort()
          + path + "/";
%>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>对比记录</title>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>css/easyui.css" />
    <link rel="stylesheet" type="text/css" href="<%=basePath%>css/icon.css" />
    <script type="text/javascript" src="<%=basePath%>js/jquery.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="<%=basePath%>js/json2.js"></script>
  </head>
  <body>
    <div id="main" class="easyui-layout" fit="true">
      <%--建个表显示记录--%>
      <table id="dataGrid" toolbar="#div_toolbar" fitColumns="true"
             fit="true"  style="width:auto;height:100%"
             data-options="pageSize:20">
      </table>
    </div>
    <div id="div_toolbar" style="">
      <span style="">
        <label style="color: #313031">任务名：</label>
        <select id="task_name" class="easyui-combobox" editable="false" style="width: 90px" panelHeight=auto></select>
        <a id="select" class="easyui-linkbutton" title="查询" iconCls="icon-search" plain="true">查询</a>
      </span>
    </div>
  </body>
  <script>
    //从表中第page条数据开始查询
    var page = 1;
    //查询size条数据 默认25条
    var size =25;
    //表结构
    var dataGrid=$('#dataGrid').datagrid({
      singleSelect: true,
      pagination : true,
      rownumbers:true,
      nowrap:false,
      fitColumns :false,
      columns: [[
        {field: 'id', title: 'id',width: '5%', hidden: false},
        {field: 'action_type',width: '8%', title: '任务名'},
        {field: 'src_database', width: '8%', title: '源数据库'},
        {field: 'src_table', width: '8%', title: '源表'},
        {field: 'tgt_database', width: '8%', title: '目标数据库'},
        {field: 'tgt_table', width: '8%', title: '目标表'},
        {field: 'from_number', width: '8%', title: '起始行'},
        {field: 'to_number', width: '8%', title: '终止行'},
        {field: 'state', width: '5%', title: '状态',
          formatter:function(value,row,index){
            if(value==0){
              return "成功";
            }else{
              return "失败";
            }
          }
        },
        {field: 'create_time', width: '17%', title: '创建时间'},
        {field: 'message', width: '17%', title: '提示信息'}
      ]]
    });

    $(function(){
      loadPage({page:page,size:size,actionType:""});
      loadActionType();
      $("#select").bind("click",function(){
        var actionType=$("#task_name option:selected").val();
        var param=({page:page,size:size,actionType:actionType});
        loadPage(param);
      })
    });


    function loadPage(param){
      $.ajax({
        url: "<%=basePath%>backupRecord/loadPage",
        type: 'post',
        timeout:20000,
        data: param,
        success:function(res){
//                  console.log(res);
                  console.log(res.data);
//                  console.log(res.data.data);
          if(res.code == 200){
            dataGrid.datagrid("loadData",res.data.data);
            total =res.data.total;
            dataGrid.datagrid('getPager').pagination({//分页对象
              pageSize: 25,
              total: res.data.total,
              pageNumber: res.data.page,
              pageList:[25,50,75,100],
              onSelectPage : function(pageNumber, pageSize) {
                var param ={page:pageNumber,size:pageSize,actionType:res.data.action_type};
                loadPage(param);
              }
            });
          } else {
            $.messager.show({
              title:'提示',
              width:250,
              height:140,
              msg:"没有任何数据！"
            });
          }
        },
        error: function (error) {
          $.messager.show({
            title:'提示',
            width:250,
            height:140,
            msg:"<div class='messager-icon messager-error'></div><div>系统繁忙，请稍后再试！</div>"
          });
        }
      });
    }



    //按任务名查询
    function loadActionType(){
        var combobox= $('#task_name').combobox({
            valueField:'id',
            textField:'action_type'
        });
        $.ajax({
            url: '<%=basePath%>backupRecord/loadActionType',
            type: 'post',
            timeout:20000,
            success:function(res){
                console.log(res.data);
                $('#task_name').combobox('loadData',res.data);
            }
        });

    }
  </script>

